<?php
    global $columns, $per_page, $is_single_product;
    do_action('jigoshop_before_shop_loop');
    $loop = 0;

    if (!isset($columns) || !$columns) 
        $columns = apply_filters('loop_shop_columns', 4);
    ob_start();
    if (!$is_single_product) {
        if (have_posts()) {
?>
    <div id="sort-form"> Sắp xếp
        <select id="sortType" onchange="onSortChange();">
            <option value="">Chọn kiểu sắp xếp</option>
            <option value="<?php 
                                $arr_params = array ( 'orderby' => 'price', 'order' => 'asc' );
                                echo add_query_arg( $arr_params, "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); 
                            ?>" <?php if($_GET["orderby"] == 'price' && $_GET["order"] == 'asc') print 'selected';?> >Giá tăng dần</option>
            <option value="<?php 
                                $arr_params = array ( 'orderby' => 'price', 'order' => 'desc' );
                                echo add_query_arg( $arr_params, "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); 
                            ?>" <?php if($_GET["orderby"] == 'price' && $_GET["order"] == 'desc') print 'selected';?> >Giá giảm dần</option>
            <option value="<?php 
                                $arr_params = array ( 'orderby' => 'rating', 'order' => 'asc' );
                                echo add_query_arg( $arr_params, "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); 
                            ?>" <?php if($_GET["orderby"] == 'rating' && $_GET["order"] == 'asc') print 'selected';?> >Đánh giá tăng dần</option>
            <option value="<?php 
                                $arr_params = array ( 'orderby' => 'rating', 'order' => 'desc' );
                                echo add_query_arg( $arr_params, "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); 
                            ?>" <?php if($_GET["orderby"] == 'rating' && $_GET["order"] == 'desc') print 'selected';?> >Đánh giá giảm dần</option>
        </select>
    </div>
            
<?php
            do_action('customize_sort_action');
        }
    }
    
    if (have_posts()) : while (have_posts()) : the_post(); $_product = new jigoshop_product( $post->ID ); $loop++;
?>
        <div id="product-1" class="summary">
            <a href="<?php echo the_permalink(); ?>" class="img">
            <?php if ( has_post_thumbnail() ) : ?>
                <?php $img = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'shop_thumbnail'); ?>
                <img src="<?php echo $img[0]; ?>" />
            <?php else : ?>
                <img src="<?php ?>" title="<?php the_title(); ?>"/>
            <?php endif; ?>
        </a>
                <a href="<?php the_permalink(); ?>" class="name" title="<?php the_title(); ?>"><?php the_title(); ?></a>
                <p class="price"><?php echo $_product->get_price_html(); ?></sup></p>
        </div>
	
    	<?php
            if ($loop==$per_page) 
                break;
        endwhile; 
    endif;

    if ($loop==0) :
        echo '<p class="info">'.__('No products found which match your selection.', 'jigoshop').'</p>';
    else :
        $found_posts = ob_get_clean();
        echo '<ul class="products">' . $found_posts . '</ul><div class="clear"></div>';
    endif;
    
    do_action('jigoshop_after_shop_loop');
